#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
import time
if sys.platform == "darwin":
    adbpath = "adb "
else:
    adbpath = "/usr/bin/adb "
if (sys.argv.__len__())<4:
    print( "参数个数少了")
    exit(0)
handset = sys.argv[1]
currentHandsetSnumber = sys.argv[2]
command = sys.argv[3]

appDict = { "微信package": "com.tencent.mm",
           "微信launch": ".ui.LauncherUI", }

def launchApp(appName, handset,currentHandsetSnumber,delay=5, forceClose=1):
    package = appDict[appName + 'package']
    launch = appDict[appName + 'launch']
    if forceClose == 1:
        os.system(adbpath + "-s "+currentHandsetSnumber + " shell am force-stop  " + package)
    else:
        pass
    os.system(adbpath + currentHandsetSnumber + " shell am start -n  " + package + "/" + launch)
    time.sleep(delay)

if command =="launchApp".strip():
    launchApp("微信",handset,currentHandsetSnumber)
